package mware_lib.communication;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class Client {
	private Socket MySocket;
	private InputStream In;
	private OutputStream Out;
	private ObjectInputStream ObjectIn;
	private ObjectOutputStream ObjectOut;
	
	public Client(String host, int port) throws UnknownHostException, IOException {
		MySocket = new Socket(host, port);
		In = MySocket.getInputStream();
		ObjectIn = new ObjectInputStream(In);
		Out = MySocket.getOutputStream();
		ObjectOut = new ObjectOutputStream(Out);
	}
	
	public Object receive() throws IOException, ClassNotFoundException {
		return ObjectIn.readObject();
	}
	
	public void send(Object message) throws IOException {
		ObjectOut.writeObject(message);
	}
	
	public void close() throws IOException {
		ObjectIn.close();
		In.close();
		ObjectOut.close();
		Out.close();
		MySocket.close();
	}
}
